package okl.lab.namesFilter.view.mediators
{
	import okl.lab.namesFilter.controller.events.UsersEvent;
	import okl.lab.namesFilter.view.interfaces.ILoadNamesList;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 *	@author "oleksandr.kulinchenko@gmail.com"
	 */
	public class LoadNamesMediator extends Mediator
	{
		[Inject]public var view:ILoadNamesList;
		public function LoadNamesMediator()
		{
			super();
		}
		
		override public function onRegister():void{
			super.onRegister();
			
			addViewListener(UsersEvent.LOAD, onLoadRequest);
			
			addContextListener(UsersEvent.UPDATED, onUsersLoaded);
		}
		
		//relay request to event-bus
		protected function onLoadRequest(event:UsersEvent):void{
			dispatch(event);
		}
		
		protected function onUsersLoaded(event:UsersEvent):void{
			view.dataProvider = event.users;
		}
	}
}